# Build recipe for fossil.
#
# Copyright (C) 2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software: you have unlimited permission
# to copy, distribute and modify it.

program=fossil
version=2.3
release=1

tarname=${program}-src-${version}.tar.gz

# Remote source(s)
fetch=http://fossil-scm.org/index.html/uv/$tarname

description="
Simple, high-reliability, distributed software configuration management.
"

homepage=https://fossil-scm.org/index.html/doc/trunk/www/index.wiki
license="2-clause BSD"

# Source documentation
docs="VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --build="$(cc -dumpmachine)" \
     || true

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"

    for file in $docs
    do
        if test -e $file
        then
            cp -p $file "${destdir}${docsdir}"
        fi
    done
}
